import java.util.Arrays;
import java.util.stream.Collectors;
class Solution {
    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> map = new HashMap<>();
        for (String str : strs) {
            char[] charArr = str.toCharArray();
            Arrays.sort(charArr);
            String key = Arrays.toString(charArr);
            List<String> keyItem = map.getOrDefault(key, new ArrayList<>());
            keyItem.add(str);
            map.put(key, keyItem);
        }
        // return map.entrySet().stream().map(entry -> entry.getValue()).collect(Collectors.toList());
        return new ArrayList<List<String>>(map.values());
    }
}
